package com.ichir.projects.uiflow.internal.executors;

import java.util.Map;

import com.ichir.projects.uiflow.ApplicationContext;
import com.ichir.projects.uiflow.ui.api.IUiAction;
import com.ichir.projects.uiflow.ui.api.IUiPart;

public class UIActionExecutor implements IUiPartExecutor {

//	private IUiPart progress;

	@Override
	public void executeUiPart(IUiPart uiPart, final ApplicationContext context,
			final Map<String, Object> attributes) {
		if (! (uiPart instanceof IUiAction)) {
			return;
		}
		System.out.println(">> execute action "+uiPart);
		final IUiAction action = (IUiAction) uiPart;

//		IUiView progressView = null;
//		progress = null;
//		if (
//				(action instanceof IUiWithProgress)
//				&&
//				(((IUiWithProgress) action).getProgress() != null)
//				) {
//			progress = ((IUiWithProgress) action).getProgress();
//			if (progress instanceof IUiView) {
//				System.out.println(">> show progress view");
////				progressView = (IUiView) progress;
//				ExecutorsRegistry.execute(progress, FlowType.VIEW, context, attributes);
//			}
//		}

		// execute action
		action.execute(context, attributes);
		
		// dispose progress
//		if (progressView != null) {
//			System.out.println(">> dipose progress view");
//			progressView.disposeView(context, attributes);
//		}
	}
}
